#include "wave.h"
#include <cmath>

/*==============================================================================
						Effects classes
==============================================================================*/
SineWave::SineWave(Video* video = NULL, Sound* sound = NULL, const std::string &filename = "",
				   float amplitude = 1.0f)
	: ParticleEffect(video, sound, filename), amplitude(amplitude), last_frequency(0.0f),
	last_intensity(0.0f)
{
}

SineWave::~SineWave()
{
}

// Updates positions of particle
void SineWave::UpdatePos(int id)
{
     float normalized_id = Normalize((float)id, float(GetMaxParticles()));

        float normalized_freq = Normalize(GetSoundFreq(), MAXFREQ);
        float smooth_freq = 1;

        float shift_x = 0.0f, shift_y = 0.0f;

        shift_x = particles[id].pos.x + particles[id].speed.x  * dt;

        shift_y = amplitude * smooth_freq * sin(normalized_id * SmoothStep(0.0f, (float)GetMaxParticles(), normalized_id)) * sin(shift_x * 1000);
        Vector2 shift(shift_x, shift_y);
        particles[id].pos = shift;
}
